﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Golos.Web.Utils;

namespace Golos.Web.handlers
{
    public class TestHandler : HandlerBase
    {
        public TestHandler(HttpContext httpContext)
            : base(httpContext)
        {
        }
        public override void Handle()
        {
            try
            {
                Guid g = new Guid("F7230B9C-6A2B-460D-8608-826EA37D2ADC");

                LogClass.WriteDebugEntry("Сгенерировал новый гуид=" + g.ToString());

                try
                {
                    Token kk = new Token(g, DateTime.Now.AddDays(7));

                    LogClass.WriteDebugEntry(kk.ToString());

                    string encryptedToken = Encrypter.EncryptString(kk.Serialize());

                    LogClass.WriteDebugEntry("encryptedToken=" + encryptedToken);

                    HttpCookie tokenCook = new HttpCookie("token", encryptedToken);
                    tokenCook.Expires.AddDays(7);
                    _httpContext.Response.Cookies.Add(tokenCook);
                    //_httpContext.Response.Redirect("/Default.aspx");

                }
                catch (Exception e)
                {
                    LogClass.WriteErrorEntry(e.ToString());
                    LogClass.WriteErrorEntry(e.StackTrace);
                }
            }
            catch (Exception e)
            {
                LogClass.WriteErrorEntry(e.ToString());
            }
        }
    }
}